//
//  ASTeaSelectClassOrSubjectViewController.m
//  AttendenceSys
//
//  Created by ld on 16/1/28.
//  Copyright © 2016年 窦芳俊. All rights reserved.
//

#import "ASTeaSelectClassOrSubjectViewController.h"

@interface ASTeaSelectClassOrSubjectViewController ()

@end

@implementation ASTeaSelectClassOrSubjectViewController

/**
 *  初始化
 *
 *  @param isSeleClass  是否选择班级

 */
- (instancetype)initWithSubOrClass:(BOOL)isSeleClass
{
    self = [super init];
    if (self)
    {
        self.bSeleClass = isSeleClass;
      
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initData];
    [self initView];
    
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)initData
{
    _teaSelectInfoArr = [[NSMutableArray alloc] init];
    if (_bSeleClass) {
        SubClassInfo* info = [[SubClassInfo alloc] init];
        info.subOrClassContent = @"1班";
        info.isSelect = NO;
        [_teaSelectInfoArr addObject:info];
        
        SubClassInfo* info1 = [[SubClassInfo alloc] init];
        info1.subOrClassContent = @"2班";
        info1.isSelect = NO;
        [_teaSelectInfoArr addObject:info1];
        
        SubClassInfo* info2 = [[SubClassInfo alloc] init];
        info2.subOrClassContent = @"3班";
        info2.isSelect = NO;
        [_teaSelectInfoArr addObject:info2];
        
        SubClassInfo* info3 = [[SubClassInfo alloc] init];
        info3.subOrClassContent = @"4班";
        info3.isSelect = NO;
        [_teaSelectInfoArr addObject:info3];
    }
    else
    {
        SubClassInfo* info = [[SubClassInfo alloc] init];
        info.subOrClassContent = @"政治";
        info.isSelect = NO;
        [_teaSelectInfoArr addObject:info];
        
        SubClassInfo* info1 = [[SubClassInfo alloc] init];
        info1.subOrClassContent = @"体育";
        info1.isSelect = NO;
        [_teaSelectInfoArr addObject:info1];
        
        SubClassInfo* info2 = [[SubClassInfo alloc] init];
        info2.subOrClassContent = @"艺术史学与建筑史学习的关系论";
        info2.isSelect = NO;
        [_teaSelectInfoArr addObject:info2];
        
        SubClassInfo* info3 = [[SubClassInfo alloc] init];
        info3.subOrClassContent = @"马克思列宁主义原理";
        info3.isSelect = NO;
        [_teaSelectInfoArr addObject:info3];
    }
}

-(void)initView
{
    _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.backgroundColor = [UIColor clearColor];
    _tableView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.scrollEnabled = YES;
    [_tableView registerClass:[TeaSelectClassOrSubjectCell class] forCellReuseIdentifier:NSStringFromClass([TeaSelectClassOrSubjectCell class])];
    [self.view addSubview:_tableView];
    
    //开始点名
    if (_bSeleClass) {
        
        //开始点名按钮
        UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, SubClassCellHeight*_teaSelectInfoArr.count, CGRectGetWidth(self.view.bounds), 100)];
        footer.backgroundColor = [UIColor clearColor];
        
        UIButton* callNameBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
//        callNameBtn.frame = CGRectMake(50, [UIScreen mainScreen].bounds.size.width/2+50,[UIScreen mainScreen].bounds.size.width-50*2,50);
        callNameBtn.frame = CGRectMake(50, 50,[UIScreen mainScreen].bounds.size.width-50*2,50);
        [callNameBtn setTitle:@"开始点名" forState:UIControlStateNormal];
        callNameBtn.layer.cornerRadius = 4.5;
        [callNameBtn addTarget:self action:@selector(callName) forControlEvents:UIControlEventTouchUpInside];
        
        [callNameBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        callNameBtn.backgroundColor = RGB(252, 120, 61);
        callNameBtn.enabled = YES;
        [footer addSubview:callNameBtn];
        _tableView.tableFooterView = footer;
        
    }
}


#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_teaSelectInfoArr count];
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TeaSelectClassOrSubjectCell* cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([TeaSelectClassOrSubjectCell class])];
    [cell setBackgroundColor:[UIColor whiteColor]];
    SubClassInfo* subOrClaInfo =  [_teaSelectInfoArr objectAtIndex:indexPath.row];
    cell.claSeleImage.hidden = !subOrClaInfo.isSelect;
    cell.subClassLab.text = subOrClaInfo.subOrClassContent;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return SubClassCellHeight;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    SubClassInfo* subclaInfo = [_teaSelectInfoArr objectAtIndex:indexPath.row];
    subclaInfo.isSelect = !subclaInfo.isSelect;
    
     [_tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
    
}

-(void)callName
{

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
